<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use app\common\widgets\MyFileUpload;

/* @var $this yii\web\View */
/* @var $model app\models\Material */
/* @var $form yii\widgets\ActiveForm */
?>


<script type="text/javascript" src="js/qiniuupload/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="js/qiniuupload/plupload/plupload.full.min.js"></script>
<script type="text/javascript" src="js/qiniuupload/plupload/i18n/zh_CN.js"></script>
<script type="text/javascript" src="js/qiniuupload/ui.js"></script>
<script type="text/javascript" src="js/qiniuupload/qiniu.js"></script>
<script type="text/javascript" src="js/qiniuupload/highlight/highlight.js"></script>
<script type="text/javascript" src="js/qiniuupload/main.js"></script>

<div class="material-form">
    
     <h4><?= Html::encode($model->isNewRecord ? '新建资料>>' : '更新资料>>') ?></h4>
    
    <div class="panel panel-default">
        <!--<div class="panel-heading text-center" style="background: #003eff;color:white">material</div>-->
        <div class="panel-body">
            <?php
            $form = ActiveForm::begin([
                        'options' => ['class' => 'form-horizontal form-group'],
                        'fieldConfig' => [
                            'template' => "{label}<div class=\"col-lg-8\">{input}</div>",
                            'labelOptions' => ['class' => 'col-lg-4', 'style' => 'margin-right:-30px'],
                        ]
            ]);
            ?>
            <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                <?= $form->field($model, 'materialno')->textInput(['maxlength' => true]) ?>
            </div>
            <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                <?= $form->field($model, 'materialtype')->dropDownList(['横向项目' => '横向项目', '纵向项目' => '纵向项目'], ['prompt' => '--请选择--']) ?>
            </div>
            <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                <?= $form->field($model, 'materialname')->textInput(['maxlength' => true]) ?>
            </div>
            <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                <?= $form->field($model, 'summary')->textarea() ?>
            </div>
            <div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
                <?= $form->field($model, 'isfinish')->dropDownList(['1' => '是', '0' => '否'], ['prompt' => '请选择']) ?>
            </div>

            <div class="col-lg-12 col-lg-push-1 col-xs-12 col-sm-12 col-md-12">
                <?php if (!$model->isNewRecord) {
                ?>
                <div class="form-group">
                    <label class="col-lg-2 control-label"><h4>已有文档</h4></label>
                    <ul class="list-unstyled project-files col-lg-12">
                        <?php
                        foreach ($model->upfiles as $document) {
                            ?>
                        <li class="col-lg-2"  style="float:left">
                                <div class="media">
                                    <div class="media-left">
                                        <a href="<?= $document->path ?>">
                                            <?php
                                                $path = $document->path;
                                                $filetyep = strtolower(substr($path, strrpos($path, '.') + 1)) ;
                                                
                                                 if ($filetyep == "xls" || $filetyep == "xlsx") {
                                                     ?>
                                             <img class="media-object" src="img/excel.png" alt="..." style="width:50px;height:50px;">
                                            <?php
                                                     
                                                 }else if($filetyep == "doc" || $filetyep == "docx"){
                                                     
                                                     ?>
                                              <img class="media-object" src="img/word.jpg" alt="..." style="width:50px;height:50px;">
                                            <?php
                                                     
                                                 }else if($filetyep == "ppt" || $filetyep == "pptx"){
                                                     ?>
                                            <img class="media-object" src="img/ppt.png" alt="..." style="width:50px;height:50px;">
                                            <?php
                                                     
                                                 }else if($filetyep == "txt"){
                                                     ?>
                                               <img class="media-object" src="img/text.png" alt="..." style="width:50px;height:50px;">
                                            <?php
                                                 }else if($filetyep == "png" || $filetyep == "jpg" || $filetyep == "jpeg" ||$filetyep == "bmp"||$filetyep == "gif"){ 
                                                     ?>
                                               <!--<img class="media-object" src="img/zhaopian.png" alt="..." style="width:50px;height:50px;">-->
                                               <img class="media-object" src="<?= $path ?>" alt="..." style="width:50px;height:50px;">
                                                     <?php
                                                 }
                                                 else{ ?>
                                            <img class="media-object" src="img/file.png" alt="..." style="width:50px;height:50px;">
                                            <?php
                                                     
                                                 }
                                                
                                            ?>
                                           
                                        </a>
                                    </div>
                                </div>
                            <a href="<?= $path ?>"><?= $document->filename ?></a>
                            </li>

                            <?php
                            }
                            ?>
                    </ul>
                 
                </div>

            <?php }
            ?>
                
            </div>
            
            
            
             <?= MyFileUpload::widget() ?>

            <div class="col-lg-12 col-xs-12 col-sm-12 col-md-12">
                <div class="form-group">
                    <?= Html::submitButton('保存', ['class' => 'btn btn-success col-lg-offset-5 col-md-offset-5']) ?>
                    <?= Html::a('返回', ['index'], ['class' => 'btn btn-primary']) ?>
                </div>
            </div>

            <?php ActiveForm::end(); ?>
        </div>
    </div>

</div>
